Repository navigation
Apply CPU, memory and pid limits to bubblewrap jails through a systemd scope - #173
Merged
M3gA-Mind merged 3 commits intoNov 12, 2026
Merged
Conversation
…d scope The bubblewrap backend claimed no resource limits: a hard request was refused and a soft one silently not applied. Run the launcher under a rootless systemd-run scope for the controllers the user manager was delegated, claim exactly those in constraint_support, and refuse a hard limit for a jail that could reach the manager and leave its scope (a shared host network, or a grant of /run or /sys). tinybox-linux exposes the scope prefix it already builds for native jails (resource_scope_argv, ScopeLimits), so both paths share it.
…out an extension check
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Tiny Sweeper reviewReviewed head: Verdict: Ready for maintainer review · Priority: none Diagnostics and supporting detailsFull summaryPull request purpose (title): Apply CPU, memory and pid limits to bubblewrap jails through a systemd scope. Tiny Sweeper completed its review; deterministic results follow. Review snapshot
Completeness: Complete Features
Tests
FindingsNo active actionable findings. Before mergeNone. How this fits togetherflowchart LR
n0["...paces_puts_nsenter_in_front_by_descriptor<br/>changed"]:::changed
n1["BubblewrapBackend<br/>changed"]:::changed
n2["Verified<br/>changed"]:::changed
n3["prepare_command<br/>changed"]:::changed
n4["verify<br/>changed"]:::changed
n5["discard"]:::impacted
n6["env"]:::impacted
n7["...riptors_reach_bwrap_and_nothing_else_does"]:::impacted
n8["tempdir"]:::impacted
n9["the_launcher_runs_with_an_empty_environment"]:::impacted
n0 -->|calls| n5
n0 -->|tests| n5
n1 -->|uses| n2
n3 -->|uses| n2
n3 -->|uses| n6
n4 -->|uses| n2
n7 -->|calls| n5
n7 -->|tests| n5
n7 -->|calls| n8
n7 -->|tests| n8
n9 -->|calls| n5
n9 -->|tests| n5
n9 -->|calls| n8
n9 -->|tests| n8
classDef changed fill:#0d4429,stroke:#238636,color:#e6edf3
classDef impacted fill:#161b22,stroke:#6e7681,color:#c9d1d9
classDef flagged fill:#5a1e02,stroke:#d93f0b,color:#ffffff
classDef blocking fill:#67060c,stroke:#f85149,color:#ffffff
Agent review detailscritique
security
tests
commits
description
Evidence and run details
|
This was referenced Nov 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The bubblewrap jail backend claimed no resource limits. A hard CPU, memory or pid requirement was refused, and a soft
resourcesbudget was silently not applied.Now the launcher runs under a rootless
systemd-run --user --scope, so the whole jail,bwrapincluded, lives in one transient cgroup holding the limits. Only the controllers the user manager was delegated are applied and claimed inconstraint_support; Disk stays unsupported.A jail that could reach the user manager could start a process outside its scope. So a hard limit is refused for a jail that shares the host network (its abstract sockets reach the manager) or that is granted
/runor/sys. A soft limit is still applied there, as a best effort.tinybox-linuxalready builds this scope prefix for native jails. It now exposes it asresource_scope_argvwithScopeLimits, so both paths share one implementation.Related issue
Closes #104. Its last open item was the known gap "resource limits" for the bwrap backend. The other items are already on main:
deny_readpaths (Refuse a missing deny_read inside a 2.1 jail's mounts, and document the mask gap #169);base_dircanonicalization, the host-alias symlink check, theINVALID_FILE_PATHassertion and the README note.Part of #27: this is the last tinybox-side item of its narrowed scope (bwrap limits).
API or behavior changes
BubblewrapBackend::constraint_supportnow reportsCpu,MemoryandPidsasEnforcedfor each controller the user manager was delegated, andUnsupportedotherwise. Before, all three were always unsupported.resourcesnow runs inside atinybox-bwrap-<pid>-<n>.scopeunit. The scope's task count also includes the two or three host-side processesbwrapruns as.Cpu/Memory/Pidsrequirement is refused withUnsupportedfor a jail that shares the host network or is granted/runor/sys.tinybox-linux:resource_scope_argvandScopeLimits. It's additive.Validation
Run on our Linux CI runner at cd3ff44, against main b0a91eb:
cargo fmt --all -- --check: clean.cargo clippy --all-targets --all-features -- -D warnings: 0 errors, the same as main.cargo build --all-targets --all-features --locked, andRUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features: ok.cargo test --all-features --workspace --locked: 1684 passed and 0 failed, with no failures unique to this branch (main: 1670 passed).TINYBOX_REQUIRE_BWRAP=1 cargo test -p tinybox-jail --test bwrap_isolation --test bwrap_fd_leak: 26 passed.cargo test -p tinybox-jail --lib bwrap: 81 passed. Nothing skipped.TINYBOX_REQUIRE_BWRAP=1 TINYBOX_REQUIRE_BWRAP_LIMITS=1 cargo test -p tinybox-jail --test bwrap_resource_limits, under a user systemd manager delegatedcpu memory pids: 2 passed. The shared-network test was run again withTINYBOX_REQUIRE_SHARED_NETWORK=1on a host without pasta, and passed.cargo test -p tinybox-module native_jail: 35 passed, nothing skipped. No transient scope units were left behind.Tests
bwrap::scope::tests(7 tests):/runor/sys;bwrap::tests:constraint_supportfollows the delegated controllers;systemd-runwithbwrapafter its separator;bwrap::launcher::tests: the scoped launcher keeps onlyXDG_RUNTIME_DIRandDBUS_SESSION_BUS_ADDRESS, and its argv is the prefix followed by the unchanged launcher.tinybox-linuxsandbox::test: the shared prefix sets only the limits asked for, ends at--, and gives each scope its own unit name. The existing native-jail argv tests cover the refactor.tests/bwrap_resource_limits.rs:native-resource-livejob already starts a user manager with delegated controllers, and now runs this suite withTINYBOX_REQUIRE_BWRAP=1 TINYBOX_REQUIRE_BWRAP_LIMITS=1, so a skip there fails. It then removes passt and runs the shared-network test again withTINYBOX_REQUIRE_SHARED_NETWORK=1.Documentation
crates/tinybox-jail/src/bwrap/mod.rs: a new "Resource limits" section, with the entry removed from "Known gaps".crates/tinybox-jail/src/bwrap/scope.rs: module docs on the scope, the task count and the escape routes.crates/tinybox-jail/README.md: the bwrap row is updated.Checklist
#[allow(...)],#[ignore], or relaxed lints.envcontents in the diff or the description